<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${servicePackageName}.mapper.sys.SysDepartmentMapper">

	<select id="getAllDepartment" resultType="${servicePackageName}.dto.DepartmentTreeDto">
		SELECT id,department_name,parent_dep_id,sort_num,0 AS isShow FROM sys_department WHERE is_enable = 0
	</select>
	
	<select id="getAllDepartmentWithUser" resultType="${servicePackageName}.dto.DepartmentTreeDto">
	<#noparse>
		SELECT
			t.id,
			t.department_name,
			t.parent_dep_id,
			t.sort_num,
			IF(ISNULL(t2.department_id) , 0 , 1 ) AS isShow
		FROM
			sys_department t
			LEFT JOIN sys_user_department t2 ON t2.department_id = t.id AND t2.user_id = #{userId}
		WHERE
			t.is_enable = 0
	</#noparse>
	</select>
	
	<select id="getMaxOrderNum" resultType="java.lang.Integer">
	<#noparse>
		SELECT IFNULL(MAX(sort_num),0) FROM sys_department WHERE parent_dep_id = #{parentDepId}
	</#noparse>
	</select>
</mapper>
